const Express = require("express");
const SymptomSubServer = require('../../servers/SymptomSub');
const ResponseHelper = require("../ResponseHelper");
const router = Express.Router();

/**
 * 获取所有检查分类
 */
router.get("/getAllSymptomSub",async(req,res)=>{
    try {
        const result = await SymptomSubServer.getAll();
        ResponseHelper.sendData(result, res);
      } catch (err) {
        ResponseHelper.sendErr(err, res);
      }
})


/**
 * 批量添加检查分类
 */
 router.post("/bulkCreateSymptomSub", async (req, res) => {
    try {
      const result = await SymptomSubServer.bulkCreate(req.body);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});

/**
 * 批量添加检查分类与症状
 */
 router.post("/bulkCreateSymptomSubAndSym", async (req, res) => {
    try {
      const result = await SymptomSubServer.bulkCreateSym(req.body);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});

/**
 * 添加检查分类
 */
 router.post("/addSymptomSub", async (req, res) => {
    try {
      const result = await SymptomSubServer.add(req.body);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});


/**
 * 更新检查分类
 */
 router.post("/updateSymptomSub/:id", async (req, res) => {
    try {
      const id =  req.params.id;
      const result = await SymptomSubServer.update(id);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});

/**
 * 根据id获取检查分类
 */
 router.post("/getSymptomSub/:id", async (req, res) => {
    try {
      const id =  req.params.id;
      const result = await SymptomSubServer.getById(id);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});


/**
 * 根据id删除检查分类
 */
 router.post("/delSymptomSub/:id", async (req, res) => {
    try {
      const id =  req.params.id;
      const result = await SymptomSubServer.delete(id);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});

module.exports = router;